var userInfo = {};
let pigNameList = ['粉红猪', '毛绒猪', '钢铁猪','青铜猪', '布偶猪', '陶瓷猪', '琉璃猪', '白银猪', '翡翠猪', '黄金猪', '白玉猪', '宝石猪', '如意猪', '梦幻猪', '福禄猪']
let pigList = []

/**
 * 获取用户登录信息
 */
function getUserInfo() {
  var value = userInfo;
  return value;
}

/**
 * 保存用户登录信息
 */
function setUserInfo(info) {
  //设置全局的userinfo
  userInfo.newUserFlag = info.newUserFlag || 0
  userInfo.userId = info.userId || ""
  userInfo.openId = info.openId || ""
  userInfo.unionId = info.unionId || ""
  userInfo.userName = info.userName || "匿名用户"
  userInfo.userHeadImg = info.userHeadImg || ""
  userInfo.userAttributes = info.userAttributes || {}
  
  console.log(userInfo)
}

/**
 * 构造猪数组数据
 */
function setPigList(levelInfo) {
	const curLevel = levelInfo
	const pList = []
	const countMax = pigNameList.length - 1
	let count = 1

	for (let i = 0; i < 50; i++) {
		const pigItem = {}
		if (count > 15) {
			count = 1
		}
		pigItem.name = pigNameList[count - 1]
		pigItem.imgUrl = "http://pig.wxgxxc.cn/pig/pigs/" + count  + ".png"
		pigItem.level = i + 1
		
		if (i === curLevel.level - 1) {
			pigItem.max = curLevel.levelGold
			pigItem.capacity = curLevel.capacity
			pigItem.status = 1
		} else if (i < curLevel.level - 1) {
			pigItem.status = 2
		} else if (i > curLevel.level - 1) {
			pigItem.status = 3
		}
		
		pList.push(pigItem)
		count++
	}
	pigList = pList
}

/**
 * 获取猪数组数据
 */
function getPigList() {
	var value = pigList;
	return value;
}

module.exports = {
  getUserInfo,
  setUserInfo,
  getPigList,
  setPigList
}